import { SetModalBoxVisible, SetModalBoxType } from './modal-box.action';
import { on, Action, createReducer } from '@ngrx/store';

export enum ModalBoxType {
    Register = 'register',
    Login = 'login',
    Tip = 'tip',
    Default = 'default'
}

export type ModalBoxState = {
    visible: boolean;
    modalType: ModalBoxType;
};

export const initializeState = {
    visible: false,
    modalType: ModalBoxType.Default,
};

const reducer = createReducer(
    initializeState,
    on(SetModalBoxVisible, (state, { visible }) => ({ ...state, visible })),
    on(SetModalBoxType, (state, { modalType }) => ({ ...state, modalType }))
);

export function modalBoxReducer(state: ModalBoxState, action: Action) {
    return reducer(state, action);
}

